﻿namespace WLFramework.Web.Binder.ValueProvider
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

    public class DictionaryValueProvider<TValue> : IValueProvider
    {
        private Dictionary<string, ValueProviderResult> values =
            new Dictionary<string, ValueProviderResult>(StringComparer.OrdinalIgnoreCase);

        public DictionaryValueProvider(IDictionary<string, TValue> dictionary)
        {
            Shield.AssertNotNull(ref dictionary, "dictionary");

            foreach (var item in dictionary)
            {
                this.values[item.Key] = new ValueProviderResult(item.Value);
            }
        }

        public ValueProviderResult GetValue(string key)
        {
            Shield.AssertNotNull(ref key, "key");

            ValueProviderResult result;
            this.values.TryGetValue(key, out result);
            return result;
        }
    }
}
